/**   
 * 项目名：phms3
 * 日期：    2019-11-22 16:35:44  
 * Copyright (c) 2015- HTSC-版权所有     
 */

package com.joysuch.wwyt.core.repository;

import com.joysuch.wwyt.core.entity.BaseBizCodeSeed;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * BaseBizCodeSeedDao
 * 
 */
public interface BaseBizCodeSeedDao extends JpaRepository<BaseBizCodeSeed, Long> {
    public Page<BaseBizCodeSeed> findAll(Specification<BaseBizCodeSeed> spec, Pageable pageable);

    public BaseBizCodeSeed save(BaseBizCodeSeed bean);

    public void delete(BaseBizCodeSeed bean);

    public BaseBizCodeSeed findByBizPoint(String bizPoint);

    public BaseBizCodeSeed findByBizPointAndTenentIdAndOrgCode(String bizPoint, Long tenentId, String orgCode);

    @Procedure(name = "biz_code_seed_generator")
    public Long getAndIncrementSeed(@Param("types") String bizPoint, @Param("tenentId") Long tenentId,
            @Param("orgCode") String orgCode);

    @Modifying
    @Query("update BaseBizCodeSeed set seed=1 where type=1")
    public void resetDailyTypeSeed();

    @Transactional
    @Modifying
    @Query(value = "update WWYT_BASE_BIZ_CODE_SEED set seed=seed+1, version=version+1 where id=:id and version=:version ",nativeQuery = true)
    public int updateBizCodeSeed(@Param("id") Long id, @Param("version") Long version);


}
